//
//  ShiLiTestingView.m
//  安好
//
//  Created by qinlongqing on 14-8-26.
//  Copyright (c) 2014年 冯凯. All rights reserved.
//

#import "ShiLiTestingView.h"
#import "ShiLiTestSelectViewController.h"

@interface ShiLiTestingView ()
{
    NSTimer *timer;
    
    ShiLiTestSelectViewController *shiLiTestSelectViewController;
}
@end

@implementation ShiLiTestingView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)willMoveToSuperview:(UIView *)newSuperview{
    [self.currentTestEyeViewController.navigationController setNavigationBarHidden:YES];
    [super willMoveToSuperview:newSuperview];
}

- (void)removeFromSuperview{
    [self.currentTestEyeViewController.navigationController setNavigationBarHidden:NO];
    [super removeFromSuperview];
}

- (void)showShiLiTesting{
    self.backgroundColor = UIColorFromRGB(0xe7f1f4);

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shiLiTestSelectViewDidShow) name:@"shiLiTestSelectViewDidShow" object:nil];
    
    UILabel *testCharacter = [[UILabel alloc]init];
    testCharacter.textAlignment = NSTextAlignmentCenter;
    testCharacter.textColor = [UIColor blackColor];
    testCharacter.font = [UIFont systemFontOfSize:self.currentTestCharacterSize];
    testCharacter.frame = CGRectMake(0, self.frame.size.height/2 - 50, kScreenWidth, 100);
    testCharacter.text = [self.shiLiTestData objectAtIndex:0];
    testCharacter.backgroundColor = [UIColor clearColor];
    [self addSubview:testCharacter];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showShiLiTestingSelectView)];
    [self addGestureRecognizer:tap];
    
    timer = [NSTimer scheduledTimerWithTimeInterval:5.f target:self selector:@selector(showShiLiTestingSelectView) userInfo:nil repeats:NO];
}

- (void)showShiLiTestingSelectView{
    [timer invalidate];
    
    shiLiTestSelectViewController = [[ShiLiTestSelectViewController alloc]init];
    shiLiTestSelectViewController.currentTestEyeViewController = self.currentTestEyeViewController;
    shiLiTestSelectViewController.shiLiTestData = self.shiLiTestData;
    [self.currentTestEyeViewController.navigationController pushViewController:shiLiTestSelectViewController animated:YES];
}

- (void)shiLiTestSelectViewDidShow{
    [self removeFromSuperview];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"shiLiTestSelectViewDidShow" object:nil];
//    NSLog(@"阶段一消失");
}
//- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
//    if ([viewController isEqual:shiLiTestSelectViewController]) {
//        self.currentTestEyeViewController.navigationController.delegate = nil;
//        [self removeFromSuperview];
//    }
//}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
